﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Kinect;

namespace KinectMenagerNamespace
{
    public class KinectGestureRecognizer
    {
        private List<KinectGesture> gestures = new List<KinectGesture>();
        private Skeleton activeSkeleton = null;

        public KinectGestureRecognizer()
        {
        }

        public void Update(Skeleton skeleton)
        {
            activeSkeleton = skeleton;
            foreach (KinectGesture gesture in gestures)
            {
                gesture.Update(skeleton);
            }
        }

        public void AddGesture(KinectGesture gesture)
        {
            gestures.Add(gesture);
        }

        public KinectGesture AddGesture(KinectGesturePart[] gestureParts, TimeSpan maxDuration)
        {
            KinectGesture gesture = new KinectGesture(gestureParts, maxDuration);
            gestures.Add(gesture);
            return gesture;
        }

        public GestureState CheckStateOfPart(KinectGesturePart part)
        {
            if (part is KinectGesturePart)
            {
                return part.Update(activeSkeleton);
            }

            if (part is TimeDependentKinectGesturePart)
            {
                TimeDependentKinectGesturePart tmp = part as TimeDependentKinectGesturePart;
                return tmp.TimeDependentUpdate(activeSkeleton);
            }

            return GestureState.Fail;
        }
    }
}
